package com.cndw.kungfu.business.gm;

import java.util.Map;

import javax.annotation.Resource;

import com.cndw.commons.util.BlankUtils;
import com.cndw.kungfu.comm.GmCommand;
import com.cndw.kungfu.domain.Notice;
import com.cndw.kungfu.event.model.BusinessNoticeHandler;
import com.cndw.kungfu.model.business.IBusinessNoticeManager;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.annotation.UnAuth;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;

/**
 * 公告接口
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-6-8 上午11:14:54
 */
@Controller
public class BusinessNotice {

	@Resource
	private IBusinessNoticeManager businessNoticeManager;

	@UnAuth
	@GmCommand
	public ResponseMessage publish(Session session, String sign, Map<String, Object> paramMap) {

		Notice notice = new Notice();
		notice.setUrl(BlankUtils.isBlank(paramMap.get("url")) ? null : paramMap.get("url").toString());
		notice.setTitle(BlankUtils.isBlank(paramMap.get("title")) ? null : paramMap.get("title").toString());
		notice.setInitialDelay(Integer.parseInt(paramMap.get("delay").toString()));
		notice.setBeginTime(Integer.parseInt(paramMap.get("begin").toString()));
		notice.setEndTime(Integer.parseInt(paramMap.get("end").toString()));

		return ResponseMessage.getSuccMessage(businessNoticeManager.publishNotice(notice));
	}

	@UnAuth
	@GmCommand
	public ResponseMessage updateNotice(Session session, String sign, Map<String, Object> paramMap) {
		Notice notice = new Notice();
		notice.setId(Integer.parseInt(paramMap.get("id").toString()));
		notice.setUrl(BlankUtils.isBlank(paramMap.get("url")) ? null : paramMap.get("url").toString());
		notice.setTitle(BlankUtils.isBlank(paramMap.get("title")) ? null : paramMap.get("title").toString());
		notice.setInitialDelay(Integer.parseInt(paramMap.get("delay").toString()));
		notice.setBeginTime(Integer.parseInt(paramMap.get("begin").toString()));
		notice.setEndTime(Integer.parseInt(paramMap.get("end").toString()));

		return ResponseMessage.getSuccMessage(businessNoticeManager.updateNotice(notice));
	}

	@UnAuth
	@GmCommand
	public ResponseMessage getNotices(Session session, String sign, int id) {
		return ResponseMessage.getSuccMessage(businessNoticeManager.loadBusinessNotices(id));
	}

	@UnAuth
	@GmCommand
	public ResponseMessage deleteNotice(Session session, String sign, int id) {
		return ResponseMessage.getSuccMessage(businessNoticeManager.deleteNotice(id));
	}

	@UnAuth
	@GmCommand
	public ResponseMessage restartNotice(Session session, String sign) {
		BusinessNoticeHandler.restart();
		return ResponseMessage.getSuccMessage(true);
	}
}
